/**
 * 市场数据类型定义
 */

// 指数数据
export interface IndexData {
  code: string;
  name: string;
  current: number;
  change: number;
  change_pct: number;
  high: number;
  low: number;
  open?: number;
  prev_close?: number;
  volume?: number;
  amount?: number;
  timestamp: string;
  error?: string;  // 数据获取错误信息
  _source?: 'websocket' | 'http';  // 数据来源标记
}

// K线数据
export interface BarData {
  timestamp: string;
  open: number;
  high: number;
  low: number;
  close: number;
  volume: number;
  amount?: number;
}

// 指数K线响应
export interface IndexBarsResponse {
  code: string;
  name: string;
  period: string;
  bars: BarData[];
  total: number;
}

// 全球指数数据
export interface GlobalIndexData {
  code: string;
  name: string;
  name_en?: string;
  current: number;
  change: number;
  change_pct: number;
  open?: number;
  close?: number;
  high?: number;
  low?: number;
  volume?: number;
  amount?: number;
  prev_close?: number;
  market_status?: 'trading' | 'pre_market' | 'after_hours' | 'closed';
  local_time?: string;
  timestamp: string;
}

// 全球指数响应
export interface GlobalIndexesResponse {
  americas: GlobalIndexData[];
  europe: GlobalIndexData[];
  hongkong: GlobalIndexData[];
  asia: GlobalIndexData[];
}

// 个股排行数据
export interface StockRankingData {
  rank: number;
  code: string;
  name: string;
  current_price: number;
  change_pct: number;
  change_amount: number;
  volume: number;
  turnover: number;
  is_limit_up?: boolean;
  is_limit_down?: boolean;
  open_price?: number;
  high?: number;
  low?: number;
}

// 排行榜响应
export interface StockRankingResponse {
  type: 'top_gainers' | 'top_losers' | 'top_turnover';
  market: string;
  stocks: StockRankingData[];
  total: number;
}

// API响应包装器
export interface ApiResponse<T> {
  success: boolean;
  data: T;
  timestamp: string;
  message?: string;
}

// K线周期类型
export type BarPeriod = '1m' | '5m' | '15m' | '30m' | '1h' | '1d' | '1w' | '1M';

// 市场类型
export type MarketType = 'all' | 'sh' | 'sz' | 'cyb';

// 排行类型
export type RankingType = 'top_gainers' | 'top_losers' | 'top_turnover' | 'most_active';

